package timing.ukulele.project.controller;

import timing.ukulele.common.Constant;
import timing.ukulele.common.ResponseResult;
import timing.ukulele.project.persistent.DictionaryContent;
import timing.ukulele.project.service.DictionaryContentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/content")
@Api("字典内容接口")
public class DictionaryContentController {

    private final DictionaryContentService dictionaryContentService;

    public DictionaryContentController(DictionaryContentService dictionaryContentService) {
        this.dictionaryContentService = dictionaryContentService;
    }

    @GetMapping("/findByDictionaryId")
    @ApiOperation("根据字典ID获取字典内容")
    public ResponseResult<List<DictionaryContent>> findByDictionaryId(
            @RequestParam(value = "dictionaryId") Long dictionaryId) {
        return dictionaryContentService.findByDictionaryId(dictionaryId);
    }

    @PostMapping("/saveContent")
    @ApiOperation("添加字典内容")
    public ResponseResult<List<DictionaryContent>> saveContent(
            @RequestBody List<DictionaryContent> content,
            @RequestHeader(Constant.USERNAME) String username) {
        return ResponseResult.success(dictionaryContentService.saveContent(content, username));
    }
}
